BASE=`pwd`
HOME=$BASE
APPLDIR=$BASE/appl
DATADIR=$BASE/data
PATH=$PATH:$BASE/ihd/bin
export APPLDIR DATADIR PATH HOME
#DESD=`awk -F= ' $1=="repo1H01" { print $2 } ' $1`
#HAST=`awk -F= ' $1=="repo1H02" { print $2 } ' $1`
#CLIE=`awk -F= ' $1=="repo1H03" { print $2 } ' $1`
#VEND=`awk -F= ' $1=="repo1H04" { print $2 } ' $1`
#STAT=`awk -F= ' $1=="repo1H05" { print $2 } ' $1`
DESD=01/01/2000
HAST=31/12/2021
ctact=./tmp/ctact
./appl/sh/ctact | awk -F^ ' {
printf "%.6d^",$2 ; printf $3"^" ; printf $4"^" ; printf "%.6d^",$5 ; printf $6"^" ; printf $7"^" ; printf "%.6d^",$8 ; printf $9"^" ; printf $10"^" ; printf $11"^" ; print $12"^"  } ' > $ctact

# |  1 H00 intern 06 15   0 | 2 H01 factur 06 01   6 | 3 H02 fechaf 10 00  12 |
# |  4 H03 montof 10 01  22 | 5 H04 cotiza 06 01  32 | 6 H05 fechac 10 00  38 |
# |  7 H06 montoc 10 01  48 | 8 H07 wrorde 06 01  58 | 9 H08 fechao 10 00  64 |
# | 10 H09 montoo 10 01  74 |11 H10 rutcli 13 00  84 |12 H11 razons 50 00  97 |
# | 13 H12 infocl 512 11 147 |14 H13 gestio 512 11 659 |15 H14 fechae 10 00 1171 |
# | 16 H15 fechap 10 00 1181 |17 H16 assocc 03 51 1191 |18 H17 status 02 52 1194 |

wrkor=./tmp/wrkor
./appl/sh/wrkor | awk -F^ ' BEGIN { desd=fec("'"$DESD"'"); hast=fec("'"$HAST"'") }
function fec(ff) {return substr(ff,7)substr(ff,4,2)substr(ff,1,2)}
{date=fec($2)}
date<desd || date>hast { next }
$12+0!="99" { ot[$2"^"$1"^"$3] += $20*$21 }
END {
for (i in ot) printf "%s^%.0f\n",i,ot[i]*1.19

} ' > $wrkor
# |  1 H00 filenu 06 01   0 | 2 H01 dateor 10 00   6 | 3 H02 cotiza 06 01  16 |
# |  4 H03 fechco 10 00  22 | 5 H04 cusdat 512 11  32 | 6 H05 obrdat 256 11 544 |
# |  7 H06 observ 256 11 800 | 8 H07 ordenc 20 01 1056 | 9 H08 fechae 10 00 1076 |
# | 10 H09 assoc  03 52 1086 |11 H10 respon 03 54 1089 |12 H11 statu  02 53 1092 |
# | 13 H12 diseno 500 15 1094 |14 H13 produc 500 15 1594 |15 H14 entreg 500 15 2094 |

# 16 D00 itemmm  2   01 | 17 D01 itemss  500 12 | 18 D02 textos  2   16 | 
# 19 D03 adicio  500 15 | 20 D04 cantid  6   01 | 21 D05 precio  10  15 | 
clien=./tmp/clien
./appl/sh/clien  | awk -F^ ' { print $1"^"$2"^"$3 } ' > $clien

# |  1 H00 regist 05 15   0 | 2 H01 rut    13 07   5 | 3 H02 razsoc 50 00  18 |
# |  4 H03 giro   40 00  68 | 5 H04 direc1 60 00 108 | 6 H05 comuna 25 00 168 |
# |  7 H06 ciudad 20 00 193 | 8 H07 region 30 00 213 | 9 H08 telefo 25 00 243 |
# | 10 H09 wsite  50 00 268 |11 H10 corree 60 00 318 |12 H11 contac 50 00 378 |
# | 13 H12 correo 60 00 428 |14 H13 observ 512 11 488 |

# 15 D00 obra    30  00 | 16 D01 direcc  50  00 | 17 D02 contac  30  00 | 
# 18 D03 telefo  50  00 | 19 D04 correo  40  00 | 

awk -F^ ' FILENAME==ARGV[1] { ot[$2$3]=$0; next }
#ot[$7$4]!="" { print ot[$7$4]"^"$0;otf[$7$4]="1"} 
ot[$7$4]!="" { print ;otf[$7$4]="1"} 
END {
	for (i in ot) if(otf[i]=="" && ot[i]!="") print ot[i] >"../../xls/es/otsf.data"
}

' $wrkor $ctact >"../../xls/es/otcf.data"

cp ../../xls/es/otsf.data tmp/ot.sf
sort -t^ -k4 ../../xls/es/otcf.data >tmp/cot.f
cotiz=./tmp/cotiz
./appl/sh/cotiz | awk -F^ ' { print $1"^"$2"^"$13"^"substr($3,1,5) } ' | sort -u > $cotiz

# |  1 H00 filenu 06 01   0 | 2 H01 dateor 10 00   6 | 3 H02 codigo 05 51  16 |
# |  4 H03 cusdat 512 11  21 | 5 H04 obras  07 59 533 | 6 H05 obrdat 256 11 540 |
# |  7 H06 obrass 07 15 796 | 8 H07 condxs 02 55 803 | 9 H08 cndxv1 256 11 805 |
# | 10 H09 observ 256 11 1061 |11 H10 totalo 10 01 1317 |12 H11 deposi 10 01 1327 |
# | 13 H12 balanc 10 01 1337 |14 H13 assoc  03 52 1347 |15 H14 statu  02 53 1350 |

# 16 D00 produc  6   54 | 17 D01 itemss  500 12 | 18 D02 textos  2   16 | 
# 19 D03 adicio  500 15 | 20 D04 costos  10  01 | 21 D05 cantid  6   01 | 
# 22 D06 pricel  10  01 | 23 D07 pricef  10  01 | 24 D08 amount  10  01 | 
# 25 D09 checko  1   17 | 
echo START
awk -F^ ' FILENAME == ARGV[1] { cot[$1]=$2"^"$3;r[$1]=$4;next }
FILENAME==ARGV[2] { cl[$1]=$2"^"$3 ; next}
FILENAME == ARGV[3] { print "SF^^^"$3"^"cot[$3]"^"$2"^"cl[r[$3]]} ' $clien $cotiz tmp/ot.sf
exit
 $;# >tmp/ot.sf2

sort -t^ -k4,4 -k1,1 tmp/cot.f tmp/ot.sf2 >../../xls/es/factot.data


exit

000001^02/04/2019^53788     ^00677|CONSTRUCTORA SANTA FE                                       
000002^24/04/2020^135660    ^01312|ASESORIAS LEGALES LETONJA Y CIA SPA                         
000003^30/10/2020^116620    ^00449|CORPORACION EDUCACIONAL SALAMANCA                           
000004^15/12/2020^1126930   ^00407|SERVICIO DE SALUD METROPLITANO SUR HOSP                     
000005^10/04/2019^468503    ^02133|LUCKY RABBIT SPA                                  MINI MARKE
000006^01/05/2019^706860    ^00095|MIGUEL ANGEL MONDACA                                        
000007^30/04/2019^936292    ^01159|INMOBILIARIA ARBOLEDA SPA                                   
000008^05/07/2019^81396     ^00095|MIGUEL ANGEL MONDACA                                        
000009^29/04/2019^78302     ^00516|CORPORACION PRINCIPE DE GALES                     COUNTRY CL
000010^29/04/2019^78302     ^00516|CORPORACION PRINCIPE DE GALES                     COUNTRY CL
==t tmp/cot.f <==
006184^11/05/2020^135660    ^000002^24/04/2020^135660    ^000344^27/04/2020^135660    ^76.768.904-7 ^ASESORIAS LEGALES LETONJA Y CIA SPA               ^
006432^17/11/2020^116620    ^000003^          ^          ^000518^04/11/2020^116620    ^65.151.772-9 ^CORPORACION EDUCACIONAL SALAMANCA                 ^
006798^05/05/2021^8328853   ^000109^10/02/2021^21150584  ^000706^10/02/2021^21150584  ^91.300.000-5 ^EMPRESA CONSTRUCTORA TECSA S.A.                   ^
007140^28/09/2021^8002231   ^000109^10/02/2021^21150584  ^000706^10/02/2021^21150584  ^91.300.000-5 ^EMPRESA CONSTRUCTORA TECSA S.A.                   ^
007141^28/09/2021^1820700   ^000109^10/02/2021^21150584  ^000706^10/02/2021^21150584  ^91.300.000-5 ^EMPRESA CONSTRUCTORA TECSA S.A.                   ^
006732^30/03/2021^205870    ^000148^22/02/2021^205870    ^000734^25/02/2021^205870    ^76.910.360-0 ^CONSTRUCTORA SANTOLAYA LTDA.                      ^
005935^06/01/2020^334271    ^000179^24/10/2019^334271    ^000103^25/11/2019^334271    ^61.602.122-2 ^HOSPITAL DE TALAGANTE                             ^
006166^24/04/2020^3421845   ^000212^12/03/2020^3421845   ^000310^12/03/2020^3442670   ^96.522.120-4 ^EMPRESA CONSTRUCTORA INGENIEROS S.A.              ^
006423^06/11/2020^3008082   ^000234^19/11/2019^6005454   ^000093^19/11/2019^6005454   ^76.910.360-0 ^CONSTRUCTORA SANTOLAYA LTDA.                      ^
007357^30/11/2021^547638    ^000256^28/10/2021^2319191   ^001206^29/10/2021^2319191   ^76.251.498-2 ^AP CONSTRUCTORA                                   ^

==> tmp/ot.sf <==
27/02/2020^000279^000547^4998
21/11/2019^000097^000240^73780
19/08/2020^000404^000844^0
09/12/2021^001285^002148^21420
05/03/2020^000292^000556^303450
18/02/2020^000253^000438^257040
07/05/2021^000859^000639^11900
11/10/2019^000053^000160^976395
04/11/2021^001213^002002^16660
15/11/2019^000087^000193^56168

	


